import { reqAddressInfo, reqOrderInfo } from "@/api/trade";
const state = {
  address: [],
  orderInfo: {},
};
const mutations = {
  //获取用户地址信息
  GETADDRESSINFO(state, address) {
    state.address = address;
  },
  GETUSERORDERINFO(state, orderInfo) {
    state.orderInfo = orderInfo;
  },
};
const actions = {
  //获取用户地址信息
  async getAddressInfo({ commit }) {
    let res = await reqAddressInfo();
    // console.log(res);
    if (res.code == 200) {
      commit("GETADDRESSINFO", res.data);
      return "ok";
    } else {
      throw new Error("fail");
    }
  },
  //获取用户订单信息
  async getUserOrder({ commit }) {
    let res = await reqOrderInfo();
    console.log(res);
    if (res.code == 200) {
      commit("GETUSERORDERINFO", res.data);
      return "ok";
    } else {
      throw new Error("fail");
    }
  },
};
const getters = {};
export default {
  state,
  mutations,
  actions,
  getters,
};
